package com.sxm.yiwei.adapters.pinche;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;
import com.sxm.yiwei.R;
import com.sxm.yiwei.beans.pinche.Route;
import com.sxm.yiwei.constant.Common;
import com.sxm.yiwei.tools.CircleTransform;
import com.sxm.yiwei.utils.DateUtil;
import com.sxm.yiwei.utils.HandleDataUtil;

import java.util.ArrayList;

/**
 * Created by Administrator on 2017/11/17.
 */

public class routeAdapter extends BaseAdapter {
    private final LayoutInflater inflater;
    private Context context;
    private ArrayList<Route> routes;
    public routeAdapter(Context context,ArrayList<Route> routes) {
        this.context=context;
        this.routes=routes;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return routes.size();
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder holder=null;
        if (view==null){
            holder=new ViewHolder();
            view=inflater.inflate(R.layout.changed_ticket_item,null);
            holder.seats=(TextView)view.findViewById(R.id.tv_transfer_fee);
            holder.total_price=(TextView)view.findViewById(R.id.tv_total_price);
            holder.imageView=(ImageView)view.findViewById(R.id.iv_icon);
            holder.phone=(TextView)view.findViewById(R.id.tv_phone);
            holder.words=(TextView)view.findViewById(R.id.tv_host_words);
            holder.startPos=(TextView)view.findViewById(R.id.tv_start_pos);
            holder.endPos=(TextView)view.findViewById(R.id.tv_end_pos);
            holder.code=(TextView)view.findViewById(R.id.tv_order_code);
            holder.departTime=(TextView)view.findViewById(R.id.tv_depart_time);
            view.setTag(holder);
        }else {
            holder=(ViewHolder)view.getTag();
        }
        Route route = routes.get(i);
        holder.seats.setText(route.getPasserRequireSeats());
        holder.total_price.setText(route.getTotalAmount());
        holder.code.setText(route.getOrderCode());
        holder.startPos.setText(route.getPinStartPoint());
        holder.endPos.setText(route.getPinEndPoint());
        holder.departTime.setText(DateUtil.times(route.getLeaveOffTime()));
        holder.phone.setText(route.getOwnerMobile());
        holder.words.setText("车主留言："+route.getPinLeaveWords());
        Picasso.with(context).load(Common.IMAGE_HOST+route.getIcon()).error(R.mipmap.morentouxiang).transform(new CircleTransform()).into(holder.imageView);

        return view;
    }
    private class ViewHolder{
        TextView seats;
        TextView total_price;
        TextView phone;
        ImageView imageView;
        TextView words;
        TextView startPos;
        TextView endPos;
        TextView code;
        TextView departTime;
    }
}
